# Copyright (c) 2024 Cooper0@qq.com

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

DIR_ARRAY := $(subst /, , $(patsubst %/, %, $(dir $(MKFILE_PATH))))
DIR_NAME := $(word $(words $(DIR_ARRAY)), $(DIR_ARRAY))

# BUILD_DIR=`/tmp/build/${DIR_NAME}`
BUILD_DIR='/tmp/build/${DIR_NAME}'

CONFIG_FILE=initial_cache.cmake

# 打开编译目标
CMAKE_OPTION = -D ENABLE_$(DIR_NAME)=ON

all: ${CONFIG_FILE}
	@cmake -S ${CMAKE_TOP_DIR} -B ${BUILD_DIR} ${CMAKE_OPTION} -C ${CONFIG_FILE} && cmake --build ${BUILD_DIR} -j 16

config_list: disclean
	@cmake -S ${CMAKE_TOP_DIR} -B ${BUILD_DIR} ${CMAKE_OPTION} -C ${CONFIG_FILE} && cmake -LH ${BUILD_DIR}

clean:
	@cmake $@ -C ${BUILD_DIR}

disclean:
	@rm -rf ${BUILD_DIR} ./bin

.PHONY: all config_list clean disclean
